summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/k_light_session.h
blob: f78d8e6899e9a74ecd7fe9b2022003ea82f11f6c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "core/hle/kernel/k_light_client_session.h"
#include "core/hle/kernel/k_light_server_session.h"
#include "core/hle/kernel/slab_helpers.h"
#include "core/hle/result.h"

namespace Kernel {

class KClientPort;
class KProcess;

// TODO: SupportDynamicExpansion for SlabHeap
class KLightSession final
    : public KAutoObjectWithSlabHeapAndContainer<KLightSession, KAutoObjectWithList> {
    KERNEL_AUTOOBJECT_TRAITS(KLightSession, KAutoObject);

private:
    enum class State : u8 {
        Invalid = 0,
        Normal = 1,
        ClientClosed = 2,
        ServerClosed = 3,
    };

public:
    static constexpr size_t DataSize = sizeof(u32) * 7;
    static constexpr u32 ReplyFlag = (1U << 31);

private:
    KLightServerSession m_server;
    KLightClientSession m_client;
    State m_state{State::Invalid};
    KClientPort* m_port{};
    uintptr_t m_name{};
    KProcess* m_process{};
    bool m_initialized{};

public:
    explicit KLightSession(KernelCore& kernel);
    ~KLightSession();

    void Initialize(KClientPort* client_port, uintptr_t name);
    void Finalize() override;

    bool IsInitialized() const override {
        return m_initialized;
    }
    uintptr_t GetPostDestroyArgument() const override {
        return reinterpret_cast<uintptr_t>(m_process);
    }

    static void PostDestroy(uintptr_t arg);

    void OnServerClosed();
    void OnClientClosed();

    bool IsServerClosed() const {
        return m_state != State::Normal;
    }
    bool IsClientClosed() const {
        return m_state != State::Normal;
    }

    Result OnRequest(KThread* request_thread) {
        R_RETURN(m_server.OnRequest(request_thread));
    }

    KLightClientSession& GetClientSession() {
        return m_client;
    }
    KLightServerSession& GetServerSession() {
        return m_server;
    }
    const KLightClientSession& GetClientSession() const {
        return m_client;
    }
    const KLightServerSession& GetServerSession() const {
        return m_server;
    }
};

} // namespace Kernel